package com.yu1996.gulimall.ware.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yu1996.common.utils.PageUtils;
import com.yu1996.common.utils.Query;

import com.yu1996.gulimall.ware.dao.WareInfoDao;
import com.yu1996.gulimall.ware.entity.WareInfoEntity;
import com.yu1996.gulimall.ware.service.WareInfoService;
import org.springframework.util.StringUtils;

@Service("wareInfoService")
public class WareInfoServiceImpl extends ServiceImpl<WareInfoDao, WareInfoEntity>
    implements WareInfoService {

  @Override
  public PageUtils queryPage(Map<String, Object> params) {
    QueryWrapper<WareInfoEntity> wrapper = new QueryWrapper<>();
      String key = (String) params.get("key");
    if (!StringUtils.isEmpty(key)) {
      wrapper.and(
          w -> {
            w.like("id", key)
                .or()
                .like("name", key)
                .or()
                .like("address", key)
                .or()
                .like("areacode", key);
          });
    }

    IPage<WareInfoEntity> page = this.page(new Query<WareInfoEntity>().getPage(params), wrapper);

    return new PageUtils(page);
  }
}
